//
//  CardBarButtonItemView.swift
//  TSListDemo
//
//  Created by 李超前 on 2020/11/22.
//  Copyright © 2020 dvlproad. All rights reserved.
//

import Foundation
import UIKit

class CardBarButtonItemView: UIView {
    var barItemLabel: UILabel?
    var clickBlock: (()->())?
    
    init(frame: CGRect, clickAction: (()->())?) {
        super.init(frame: frame)
        
        self.clickBlock = clickAction
        
        self.backgroundColor = #colorLiteral(red: 0.9254902005, green: 0.2352941185, blue: 0.1019607857, alpha: 1)
        self.layer.masksToBounds = true
        
        let rightBarItemImageView: UIImageView = UIImageView.init()
        rightBarItemImageView.image = UIImage.init(named: "icon_like")
        rightBarItemImageView.layer.masksToBounds = true
        self.addSubview(rightBarItemImageView)
        rightBarItemImageView.snp_makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        let rightBarItemLabel: UILabel = UILabel.init(frame: .zero)
        rightBarItemLabel.textColor = UIColor.black
        rightBarItemLabel.font = UIFont.systemFont(ofSize: 14)
        self.addSubview(rightBarItemLabel)
        rightBarItemLabel.snp_makeConstraints { (make) in
            make.right.equalToSuperview().offset(-2)
            make.bottom.equalToSuperview().offset(-2)
            make.width.height.equalTo(20)
        }
        self.barItemLabel = rightBarItemLabel
        

        let tapGR: UITapGestureRecognizer = UITapGestureRecognizer.init(target: self, action: #selector(self.__clickAction))
        self.addGestureRecognizer(tapGR)
    }
    
    @objc func __clickAction(sender: UITapGestureRecognizer) {
        if self.clickBlock != nil {
            self.clickBlock!()
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
